<?php

class FormsController extends FormController
{

  protected $orderField = 'form_position';

  protected $sortable = true;

  protected function initialize()
  {
    parent::initialize();

    $select = new FormElement_Select('form_select', 'Select');
    $select->options = array('Y' => 'Lorem ipsum dolor', 'N' => 'Sed ut perspiciatis');

    $images = new FormElement_Images('form_id', 'Images');
    $images->foreignKey = 'image_form_id';
    $images->primaryKey = 'image_id';
    $images->table = 'forms_images';

    $link = new FormElement_Link('form_id', 'Images');
    $link->foreignKey = 'image_form_id';
    $link->url = '/admin/forms/images';

    $position = new FormElement_Select('form_position', 'Position');
    $position->options = sy_array_to_options($this->Form->gateway()->findAll(array('select' => 'form_position', 'orderBy' => 'form_position')), 'form_position', 'form_position');
    $position->showEmpty = false;

    $group = new FormGroup('group1', 'Group 1');

    //$this->Form->setRecursivity('form_parent_id', 'form_left', 'form_right', 'form_text');

    $this->Form->addElement(new FormElement_Text('form_text', 'Text'));
    $this->Form->addElement(new FormElement_Textarea('form_textarea', 'Textarea'));
    //$this->Form->addElement(new FormElement_Password('form_password', 'Password'));
    $this->Form->addElement(new FormElement_DateTime('form_datetime', 'Date/Time'));
    $this->Form->addElement($link);
    $this->Form->addElement($group);

    $this->Form->addElement($position, Form::ACTION_CREATE | Form::ACTION_EDIT);

    $group->addElement($select);
    $group->addElement($images, Form::ACTION_ALL ^ Form::ACTION_INDEX);
    //$group->addElement(new FormElement_Position('form_position', 'Position'));
    //$group->addElement(new FormElement_Image('form_image', 'Image'));

    $filter0 = new FormFilter_Select('form_text', 'Text');
    $filter1 = new FormFilter_Select('form_select', 'Select');
    $filter2 = new FormFilter_String('form_textarea', 'Text');

    $filter3 = new FormFilter_DateTime('form_datetime', 'Since');
    $filter3->type = FormFilter_DateTime::SINCE;

    $filter4 = new FormFilter_DateTime('form_datetime', 'Until');
    $filter4->type = FormFilter_DateTime::UNTIL;

    $this->Form->addFilter($filter0);
    $this->Form->addFilter($filter1);
    $this->Form->addFilter($filter2);
    $this->Form->addFilter($filter3);
    $this->Form->addFilter($filter4);
  }

}
